package org.cscarioni

class Sprint {
	String name
	Panel panel
	Project project
	Date startDate
	Date endDate
	int daysOfWork
	int storyPoints
	int storyPointsLeft
	static transients = [ "daysOfWork" ,"storyPoints","storyPointsLeft"] 
	static belongsTo=[Project]
    static constraints = {
		estimatedTimes(nullable:true)
		startDate(nullable:true)
		endDate(nullable:true)
		storyPoints(nullable:true)
		tasks(nullable:true)
    }
	Set estimatedTimes
	Set tasks
	static hasMany=[estimatedTimes:EstimatedTimeHistoryForSprint,tasks:Card]
	String toString(){
		"Sprint $name (${project?.name})"
	}
	static mapping = {
		estimatedTimes(sort:'day')
	}
	public int getDaysOfWork(){
		return endDate-startDate
	}
	
	public int getStoryPoints(){
		def suma=0
		tasks.each{suma += it.estimatedTime}
		return suma
	}
	public int getStoryPointsLeft(){
		def suma=0
		tasks.each{suma += it.remainingTime}
		return suma
	}
}
